<?php
class Tag extends Controller {
	function __construct() {
		parent::__construct();
	}

	function index() {
		error_reporting(E_ALL ^ E_NOTICE);
		$this->load->model("Tag_model","tag");
		$this->tag->conndb();
		$search = array();
		$tags = $this->tag->retrive($search,'tag_sort asc,tag_id asc');
		$data = array(
			'tags'=>$tags
		);
		$this->load->view("tag",$data);
	}
	
	function publish() {
		$id = $this->input->post("tag_id");
		error_reporting(E_ALL ^ E_NOTICE);
		$this->load->model("Tag_model","tag");
		$this->tag->conndb();
		if($this->tag->publish($id)) {
			echo 99;
		};
	}

	function lock() {
		$id = $this->input->post("tag_id");
		error_reporting(E_ALL ^ E_NOTICE);
		$this->load->model("Tag_model","tag");
		$this->tag->conndb();
		if($this->tag->lock($id)) {
			echo 99;
		};
	}
	function save() {
		error_reporting(E_ALL ^ E_NOTICE);
		$this->load->model("Tag_model","tag");
		$this->tag->conndb();
		$data = json_decode($this->input->post("data"));
		$i = 0;
		foreach($data as $v) {
			$taginfo = explode("||",$v);
			$data = array(
				"tag_name"=>mb_convert_encoding($taginfo[1],"gbk","utf-8"),
				"tag_css"=>$taginfo[2],
				"tag_img"=>$taginfo[3],
				"tag_sort"=>$i++
			);
			if($this->tag->exists($taginfo[0])) {
				$this->tag->update($data,$taginfo[0]);
			} else {
				$this->tag->create($data);
			}
		}
	}
}
?>